package 链表.easy;

/**
 * @author Lw中
 * @date 2020/10/4 10:21
 */
public class BaSan {

    class ListNode {
        int val;
        ListNode next;
        ListNode(int x) {
            val = x;
            next = null;
        }
    }

    /**
     * 删除排序链表中的重复元素
     * @param head
     * @return
     */
    public static ListNode deleteDuplicates(ListNode head) {
        /* 使用双指针 */
        ListNode low = head;
        ListNode fast = head;
        while (fast != null) {
            if (low.val == fast.val) {
                low.next = fast.next;
            } else {
                low = low.next;
            }
            fast = fast.next;
        }
        return head;
    }

    public static void main(String[] args) {

    }

}
